//
//  RCMessageNotifyListDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-11-17.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMessageNotifyListDataModel.h"
#import "TravelException.h"
#import "KFObjectExtension.h"

@implementation RCMessageNotifyListItemDataModel
@synthesize content = _content;
@synthesize avatar = _avatar;
@synthesize datetime = _datetime;
@synthesize title   = _title;
@synthesize status = _status;

- (void) dealloc
{
    KF_RELEASE_SAFELY(_content);
    KF_RELEASE_SAFELY(_avatar);
    KF_RELEASE_SAFELY(_datetime);
    KF_RELEASE_SAFELY(_title);
    [super dealloc];
}


@end


@implementation RCMessageNotifyListDataModel

// 将JSON数据解析为数据模型
-(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    
    // 分配数据模型对象内存
    RCMessageNotifyListDataModel *retObject = nil;
    retObject = [[RCMessageNotifyListDataModel alloc] init];
    if ( nil == retObject )
        return retObject;
    
    NSMutableArray *listItems = [[NSMutableArray alloc] init];
    
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.pn     = [dataDic intValueForKey:@"pn" defaultValue:0];
    retObject.rn     = [dataDic intValueForKey:@"rn" defaultValue:0];
    retObject.total  = [dataDic intValueForKey:@"total" defaultValue:0];
    
    NSArray *dataItems = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dataItems) {
        dataItems = [dataDic arrayValueForKey:@"items" defaultValue:nil];
    }
    for (NSDictionary *dic in dataItems) {
        RCMessageNotifyListItemDataModel *item = [[RCMessageNotifyListItemDataModel alloc] init];
        item.content = [dic stringValueForKey:@"content" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.avatar = [dic stringValueForKey:@"avatar" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.datetime = [dic stringValueForKey:@"datetime" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.title = [dic stringValueForKey:@"title" defaultValue:@"" operation:NSStringOperationTypeNone];

        item.status = [dic intValueForKey:@"status" defaultValue:0];
        [listItems addObject:item];
        [item release];
    }
    retObject.listItems = listItems;
    [listItems release];
    
    // 返回结果数据模型
    return [retObject autorelease];
}


@end
